package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceWard;
import com.ruoyi.service.service.IServiceWardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病区Controller
 * 
 * @author ZDL
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/service/ward")
public class ServiceWardController extends BaseController
{
    @Autowired
    private IServiceWardService serviceWardService;

    /**
     * 查询病区列表
     */
    @PreAuthorize("@ss.hasPermi('service:ward:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceWard serviceWard)
    {
        startPage();
        List<ServiceWard> list = serviceWardService.selectServiceWardList(serviceWard);
        return getDataTable(list);
    }

    /**
     * 导出病区列表
     */
    @PreAuthorize("@ss.hasPermi('service:ward:export')")
    @Log(title = "病区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceWard serviceWard)
    {
        List<ServiceWard> list = serviceWardService.selectServiceWardList(serviceWard);
        ExcelUtil<ServiceWard> util = new ExcelUtil<ServiceWard>(ServiceWard.class);
        util.exportExcel(response, list, "病区数据");
    }

    /**
     * 获取病区详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:ward:query')")
    @GetMapping(value = "/{wardId}")
    public AjaxResult getInfo(@PathVariable("wardId") Long wardId)
    {
        return success(serviceWardService.selectServiceWardByWardId(wardId));
    }

    /**
     * 新增病区
     */
    @PreAuthorize("@ss.hasPermi('service:ward:add')")
    @Log(title = "病区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceWard serviceWard)
    {
        return toAjax(serviceWardService.insertServiceWard(serviceWard));
    }

    /**
     * 修改病区
     */
    @PreAuthorize("@ss.hasPermi('service:ward:edit')")
    @Log(title = "病区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceWard serviceWard)
    {
        return toAjax(serviceWardService.updateServiceWard(serviceWard));
    }

    /**
     * 删除病区
     */
    @PreAuthorize("@ss.hasPermi('service:ward:remove')")
    @Log(title = "病区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wardIds}")
    public AjaxResult remove(@PathVariable Long[] wardIds)
    {
        return toAjax(serviceWardService.deleteServiceWardByWardIds(wardIds));
    }
}
